package com.yuandian.management.utils;

import com.yuandian.management.socket.SocketInitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA加密工具类
 * @author tangqingchun
 * @date 2019年10月9日
 *
 */
public class SHAUtils {
	
	private static Logger log = LoggerFactory.getLogger(SHAUtils.class);

    public static String encrypt(String content) {
    	String contentEncrypt = content + SocketInitConfig.getSocketPassword();
    	//log.info("加密前的数据-->" + contentEncrypt);
    	BigInteger sha = null;
    	byte[] contentBytes = contentEncrypt.getBytes();
    	String result = null;
    	try {
			MessageDigest messageDigest = MessageDigest.getInstance("SHA");
			messageDigest.update(contentBytes);
			sha = new BigInteger(messageDigest.digest());
			result = sha.toString(32);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
    	//log.info("加密后的数据-->" + result);
    	return result;
    }
}
